package en.edu.sdjzu.xg.eagle.hairsalon.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.cl.annotation.IgnoreAuth;
import com.cl.entity.HuiyuankaxinxiEntity;
import com.cl.entity.view.HuiyuankaxinxiView;
import com.cl.service.HuiyuankaxinxiService;
import com.cl.utils.MPUtil;
import com.cl.utils.PageUtils;
import com.cl.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 会员卡信息
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-04 18:14:25
 */
@RestController
@RequestMapping("/huiyuankaxinxi")
public class HuiyuankaxinxiController {
    @Autowired
    private HuiyuankaxinxiService huiyuankaxinxiService;









    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,HuiyuankaxinxiEntity huiyuankaxinxi,
                                                                                            @RequestParam(required = false) Double jiageStart,
                    @RequestParam(required = false) Double jiageEnd,
                                            HttpServletRequest request){
                                    EntityWrapper<HuiyuankaxinxiEntity> ew = new EntityWrapper<HuiyuankaxinxiEntity>();
                                                                                                                                        if(jiageStart!=null) ew.ge("jiage", jiageStart);
                    if(jiageEnd!=null) ew.le("jiage", jiageEnd);
                                                        
        
        
        PageUtils page = huiyuankaxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huiyuankaxinxi), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,HuiyuankaxinxiEntity huiyuankaxinxi,
                @RequestParam(required = false) Double jiageStart,
                @RequestParam(required = false) Double jiageEnd,
		HttpServletRequest request){
        EntityWrapper<HuiyuankaxinxiEntity> ew = new EntityWrapper<HuiyuankaxinxiEntity>();
                if(jiageStart!=null) ew.ge("jiage", jiageStart);
                if(jiageEnd!=null) ew.le("jiage", jiageEnd);

		PageUtils page = huiyuankaxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, huiyuankaxinxi), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( HuiyuankaxinxiEntity huiyuankaxinxi){
       	EntityWrapper<HuiyuankaxinxiEntity> ew = new EntityWrapper<HuiyuankaxinxiEntity>();
      	ew.allEq(MPUtil.allEQMapPre( huiyuankaxinxi, MPUtil.camelToSnake("huiyuankaxinxi")));
        return R.ok().put("data", huiyuankaxinxiService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(HuiyuankaxinxiEntity huiyuankaxinxi){
        EntityWrapper< HuiyuankaxinxiEntity> ew = new EntityWrapper< HuiyuankaxinxiEntity>();
 		ew.allEq(MPUtil.allEQMapPre( huiyuankaxinxi, MPUtil.camelToSnake("huiyuankaxinxi")));
		HuiyuankaxinxiView huiyuankaxinxiView =  huiyuankaxinxiService.selectView(ew);
		return R.ok("查询会员卡信息成功").put("data", huiyuankaxinxiView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        HuiyuankaxinxiEntity huiyuankaxinxi = huiyuankaxinxiService.selectById(id);
		huiyuankaxinxi = huiyuankaxinxiService.selectView(new EntityWrapper<HuiyuankaxinxiEntity>().eq("id", id));
        return R.ok().put("data", huiyuankaxinxi);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        HuiyuankaxinxiEntity huiyuankaxinxi = huiyuankaxinxiService.selectById(id);
		huiyuankaxinxi = huiyuankaxinxiService.selectView(new EntityWrapper<HuiyuankaxinxiEntity>().eq("id", id));
        return R.ok().put("data", huiyuankaxinxi);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HuiyuankaxinxiEntity huiyuankaxinxi, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(huiyuankaxinxi);
        huiyuankaxinxiService.insert(huiyuankaxinxi);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody HuiyuankaxinxiEntity huiyuankaxinxi, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(huiyuankaxinxi);
        huiyuankaxinxiService.insert(huiyuankaxinxi);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    public R update(@RequestBody HuiyuankaxinxiEntity huiyuankaxinxi, HttpServletRequest request){
        //ValidatorUtils.validateEntity(huiyuankaxinxi);
        huiyuankaxinxiService.updateById(huiyuankaxinxi);//全部更新
        return R.ok();
    }



    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        huiyuankaxinxiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    	









}
